//
//  WebViewController.swift
//  ToBeBigFE
//
//  Created by mingo on 2020/2/8.
//  Copyright © 2020 com.example. All rights reserved.
//

import UIKit
import WebKit

class WebViewController: UIViewController, WKUIDelegate, WKNavigationDelegate {

    var webView: WKWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let config = WKWebViewConfiguration()
        let birdge = BridgeHandler()
        config.userContentController.add(birdge, name: "iOSBridge")
        
        webView = WKWebView(frame: self.view.frame, configuration: config)
        webView.uiDelegate = self
        self.view.addSubview(webView)
        
        birdge.webView = webView
        birdge.viewController = self
        birdge.initModules()
        
        let dataStore = WKWebsiteDataStore.default()
        let dateFrom: Date = Date(timeIntervalSince1970: 0)
        dataStore.removeData(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes(), modifiedSince: dateFrom) {}
        
        let url = URL(string: getLoadUrl())!
        print("load \(url)")
        let request = URLRequest(url: url)
        webView.load(request)
    }
    
    func getLoadUrl() -> String {
        return ""
    }
}
